package com.example.controller;

import com.example.common.annotation.OperLog;
import com.example.common.annotation.RepeatSubmit;
import com.example.common.enums.LogType;
import com.example.common.utils.R;
import com.example.system.entity.Menu;
import com.example.system.service.IMenuService;
import io.swagger.annotations.Api;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author 王鹤蒲
 * @since 2023-08-13
 */
@Api(tags = "菜单信息API",description="提供菜单信息相关的 REST API")
@RestController
@RequestMapping("/menu")
public class MenuController {

    @Autowired
    private IMenuService iMenuService;


    @RequestMapping(value="/selectAll",method= RequestMethod.GET)
    @ResponseBody
    public R selectAll(@RequestParam(defaultValue = "") String name){
        return R.success(iMenuService.findAll(name));
    }

    @RequestMapping(value="/save",method=RequestMethod.POST)
    @RepeatSubmit(lockTime = 5)
    public R save(@RequestBody Menu menu){
      return iMenuService.insert(menu);
    }

    @OperLog(operation = "菜单管理",type = LogType.UPDATE)
    @RepeatSubmit(lockTime = 5)
    @RequestMapping(value="/edit",method=RequestMethod.POST)
    public R edit(@RequestBody Menu menu){
        return iMenuService.update(menu);
    }


    @OperLog(operation = "菜单管理",type = LogType.DELETE)
    @RequestMapping(value="/delete/{id}",method=RequestMethod.DELETE)
    @ResponseBody
    public R deleteById(@PathVariable("id") Integer id){
        return iMenuService.deleteById(id);
    }

    @OperLog(operation = "菜单管理",type = LogType.BATCH_DELETE)
    @RequestMapping(value="/deleteBatch",method=RequestMethod.POST)
    @ResponseBody
    public R deleteByIds(@RequestBody Integer []ids){
        return iMenuService.deleteByIds(ids);
    }


    @RequestMapping(value="/getIconList",method=RequestMethod.GET)
    @ResponseBody
    public R  getIconList(){
        return iMenuService.getIconList();
    }


    @RequestMapping(value="/ids",method=RequestMethod.GET)
    @ResponseBody
    public R selectAllMenuIds(){
        return iMenuService.selectAllMenuIds();
    }

}

